<template>
  <div class="constentmain">
    <list-table-new v-bind="tableSetting" ref="klTable"></list-table-new>
    <dialogPublic
      :title="title"
      :show.sync="show"
      v-if="show"
      width="60%"
      @doSubmit="doSubmit"
      @doClose="doClose"
    >
      <editPage ref="editPage" :id="currentRowId" />
    </dialogPublic>
  </div>
</template>
<script>
import {
  queryClassPlanList,
  addOrUpdateClassPlan,
  deleteClassPlan,
} from "@/api/operationManagement/runningSchedule.js";
import editPage from "./editPage.vue";
export default {
  components: {
    editPage,
  },
  data() {
    return {
      title: "",
      show: false,
      currentRowId: "",
      tableSetting: {
        selectionShow: false,
        pageConfig: {
          pageCode: "classPlan",
          userId: this.$store.getters.userInfo.namePy,
        },
        searchObj: {
          searchMethod: (params, sortStr) => {
            this.getTableData(params, sortStr);
          },
          queryData: {
            page: 1,
            pageSize: 15,
          },
          searchArr: [
            {
              type: "organization",
              label: "值班单位",
              model: "deptName",
              idsStr: "deptId",
            },
            {
              type: "input",
              label: "方案名称",
              model: "name",
              placeholder: "请输入方案名称",
            },
            {
              type: "select",
              label: "值班人员类型",
              model: "staffType",
              multiple: true,
              option: this.$store.getters.dirtData("operation_staff_type"),
            },
            {
              type: "userOnly",
              label: "创建人",
              model: "createByName",
              idsStr: "createBy",
            },
            {
              type: "daterange",
              label: "创建时间",
              model: "createTime",
            },
          ],
        },
        //过滤器的值
        filterFormData: {},
        //过滤器的默认值
        defaultFilterData: {},
        userCustomData: [],
        actionList: [
          {
            name: "新增",
            icon: "el-icon-plus",
            disabled: !this.$store.getters.isBtnAuth("add"), //控制按钮的禁用
            content: "未授权功能", //禁用提示内容
            method: (row) => {
              this.add();
            },
          },
        ],
        tableMethods: {
          //点击行的方法
          rowClick: (row) => {},
        },
        column: [
          {
            label: "值班单位",
            prop: "deptName",
            sortable: "custom",
          },
          {
            label: "方案名称",
            prop: "name",
            sortable: "custom",
          },
          {
            label: "值班人员类型",
            prop: "staffType",
            sortable: "custom",
            formatter: (row) => {
              return this.$store.getters.fineDirtDataName(
                "operation_staff_type",
                row.staffType
              );
            },
          },
          {
            label: "创建人",
            prop: "createByName",
          },
          {
            label: "创建时间",
            prop: "createTime",
            sortable: "custom",
          },
          {
            label: "操作",
            textAlign: "center",
            type: "button",
            buttonArr: [
              {
                text: "编辑",
                isShow: () => {
                  return true;
                },
                disabled: !this.$store.getters.isBtnAuth("edit"), //控制按钮的禁用
                content: "未授权功能", //禁用提示内容
                methods: (row, index) => {
                  this.currentRowId = row.id;
                  this.title = "编辑班别方案";
                  this.show = true;
                },
              },
              {
                text: "删除",
                isShow: () => {
                  return true;
                },
                disabled: !this.$store.getters.isBtnAuth("delete"), //控制按钮的禁用
                content: "未授权功能", //禁用提示内容
                methods: (row, index) => {
                  this.delete(row);
                },
              },
            ],
          },
        ],
      },
    };
  },
  mounted() {
    this.$refs.klTable.getTableConfig();
    this.init();
  },
  methods: {
    init() {
      this.$refs.klTable.searchData();
    },
    //获取列表数据
    getTableData(params, sortStr) {
      let queryData = Object.assign({}, params);
      if (sortStr.length > 0) {
        queryData.orders = sortStr;
      }
      queryClassPlanList(queryData).then((res) => {
        this.$set(this.tableSetting, "tableData", res.data.list);
        this.$set(this.tableSetting, "totalNumber", res.data.total);
      });
    },
    //删除班别方案
    delete(row) {
      this.$confirm("确定要删除选中数据吗", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteClassPlan({ id: row.id }).then((res) => {
            if (res.code === 200) {
              this.$message.success(res.description);
              this.$refs.klTable.searchData();
            }
          });
        })
        .catch((e) => {});
    },
    add() {
      this.title = "新增班别方案";
      this.currentRowId = "";
      this.show = true;
    },
    //提交上传表单
    async doSubmit() {
      try {
        let formData = await this.$refs.editPage.getFormData();
        if (formData) {
          let res = await addOrUpdateClassPlan(formData);
          this.$message.success(res.description);
          this.show = false;
          this.$refs.klTable.searchData();
        }
      } catch (error) {
        console.log(error);
      }
    },
    doClose() {
      this.show = false;
    },
  },
};
</script>
<style lang="less" scoped>
.constentmain {
  width: 100%;
  height: calc(100% - 10px);
}
</style>